package org.walklink.walklinkdemo.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author lidishan
 */
@Slf4j
@RestController
public class IndexController {

    @ResponseBody
    @PostMapping("/index/returnStr")
    public Object returnStr(@RequestParam(value = "v", required = false) String v) throws Exception {
        log.info("随便打个日志");
//        Thread.sleep(new Random().nextInt(100));
//        aFun("A");
//        bFun("B");
        return String.format("returnStr: %s", v);
    }

    private void aFun(String a) {
        System.out.println("调用a方法：" + a);
        cFun("C");
    }
    private void bFun(String str) {
        System.out.println("调用b方法：" + str);
    }
    private void cFun(String str) {
        System.out.println("调用c方法：" + str);
    }




    private void tmpFun() {
        List<Map<String, String>> list = new ArrayList<>(10);
        Map<String, String> map = new HashMap<>(16);
        map.put("a", "1-aaa");
        map.put("c", "11");
        Map<String, String> map2 = new HashMap<>(16);
        map2.put("b", "2-bbb");
        list.add(map);
        list.add(map2);
        StringBuilder res = new StringBuilder();
        list.forEach(item -> item.forEach((key, val) -> {
            res.append(val.substring(val.lastIndexOf("-") + 1)).append(",");
        }));
        res.deleteCharAt(res.length() - 1);
    }

}
